/**
 * @title   通过原型继承
 * @author  wsq
 * @date   2022-4-10
 */

if(typeof Object.beget !=='function') {
    Object.beget = function (o) {
        var F =function (){ };
        F.prototype = o;
        return new F;
    };
}

// 构造函数
var myMammal = {
    name : '小白',
    get_name: function () {
        return this.name;
    },
    says : function () {
        return this.saying ||'';
    }
};

// 构建实例
var myCat = Object.beget(myMammal);
myCat.name='小黑';
myCat.saying='hello';
myCat.purr = function(n) {
    console.log('我是purr');
}
myCat.get_name = function() {
    return this.says() + ' ' + this.name + ' '+this.says();
};

console.log(myCat.name);  //小黑
myCat.purr();  // 我是purr
console.log(myCat.says());  //hello
console.log(myCat.get_name());    //hello 小黑 hello